import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import Editor from 'components/Editor';

export default (self) => [
    {
        title: '标题',
        name: 'title',
        tableItem: {},
        searchItem: {
            group: 'abc'
        },
        formItem: {
            rules: [
                {
                    required: true,
                    message: '请输入标题'
                }
            ]
        },
    },
    {
        title: '作者',
        name: 'user',
        tableItem: {},
    },
    {
        title: '标签',
        name: 'tags',
        tableItem: {},
        formItem: {},
        searchItem: {
            group: 'abc'
        },
    },
    {
        title: '直接上传',
        name: 'thumbnail_arr',
        formItem: {
            type: 'upload',
            listType: 'picture',
            action: '/system/upload/?savePath=article', // 后台接口 例：/uploadFile 会走代理
            fileName: 'file', // 后台接收的名字
            rules: [
                {
                    required: true,
                    message: '请选择图片'
                }
            ],
            maxFileSize: 1000, // 最大限制 kb
            max: 1
        }
    },
    {
        title: '描述',
        name: 'describe',
        tableItem: {},
        formItem: {
            type: 'textarea',
            rows: 5
        }
    },
    {
        title: '内容',
        name: 'content',
        formItem: {
            type: 'custom',
            render: (record, form) => {
                const { getFieldDecorator } = form;
                return (
                    <div>
                        {getFieldDecorator('content', {
                            initialValue: record && record.content
                        })(<Editor />)}
                    </div>
                )
            }
        },
    },
    {
        title: '状态',
        name: 'status_check',
        dict: [{ code: 1 }],
        formItem: {
            type: 'checkbox',
            initialValue: [1]
        }
    },
    {
        title: '状态',
        name: 'status',
        dict: [{ code: true, codeName: '是' }, { code: false, codeName: '否' }],
        searchItem: {
            type: 'select'
        },
        tableItem: {
            render: (value, record) => {
                return <DataTable.Oper>
                    <Icon type={value ? 'check' : 'close'} style={value ? { color: 'green' } : { color: 'red' }} ></Icon>
                </DataTable.Oper>
            }
        }
    },
    {
        title: '置顶',
        name: 'is_top_check',
        dict: [{ code: 1 }],
        formItem: {
            type: 'checkbox',
            initialValue: []
        },
    },
    {
        title: '置顶',
        name: 'is_top',
        tableItem: {
            render: (value, record) => {
                return <DataTable.Oper>
                    <Icon type={value ? 'check' : 'close'} style={value ? { color: 'green' } : { color: 'red' }} ></Icon>
                </DataTable.Oper>
            }
        }
    },
    {
        title: '热门',
        name: 'is_hot_check',
        dict: [{ code: 1 }],
        formItem: {
            type: 'checkbox',
            initialValue: []
        },
    },
    {
        title: '热门',
        name: 'is_hot',
        tableItem: {
            render: (value, record) => {
                return <DataTable.Oper>
                    <Icon type={value ? 'check' : 'close'} style={value ? { color: 'green' } : { color: 'red' }} ></Icon>
                </DataTable.Oper>
            }
        }
    },
    {
        title: '推荐',
        name: 'is_recommend_check',
        dict: [{ code: 1 }],
        formItem: {
            type: 'checkbox',
            initialValue: []
        },
    },
    {
        title: '热门',
        name: 'is_recommend',
        tableItem: {
            render: (value, record) => {
                return <DataTable.Oper>
                    <Icon type={value ? 'check' : 'close'} style={value ? { color: 'green' } : { color: 'red' }} ></Icon>
                </DataTable.Oper>
            }
        }
    },
    {
        title: '浏览量',
        name: 'brown_count',
        tableItem: {},
    },
    {
        title: '收藏量',
        name: 'collect_count',
        tableItem: {},
    },
    {
        title: '点赞量',
        name: 'like_count',
        tableItem: {},
    },
    {
        title: '创建时间',
        name: 'create_time',
        tableItem: {},
    },
    {
        title: '操作',
        tableItem: {
            width: 90,
            fixed: 'right',
            render: (text, record) => (
                <DataTable.Oper>
                    <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
                        <Icon type="edit" />
                    </Button>
                    <Button tooltip="删除" onClick={e => self.onDelete(record)}>
                        <Icon type="trash" />
                    </Button>
                </DataTable.Oper>
            )
        }
    }
];
